{extend name="base:base" /}
{block name="body"}
<div class="layui-tab layui-tab-brief" lay-filter="category">
    <ul class="layui-tab-title">
        <li class="layui-this">基础</li>
        <li>扩展</li>
    </ul>
    <form class="layui-tab-content layui-form" method="post" action="{:Url::build('renew')}" >
        <div class="layui-tab-item layui-show">
            <div class="layui-row">
                <div class="layui-col-xs12 layui-col-md5">
                    <div class="layui-form-item">
                        <label class="layui-form-label">上级分类</label>
                        <div class="layui-input-block">
                            <div class="layui-form-mid layui-word-aux">{$category.title ?? '无'}</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">分类名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" value="{$info.title ?? ''}" lay-verify="required"
                                   placeholder="请输入内容" class="layui-input">
                            <div class="layui-form-mid layui-word-aux">名称不能为空</div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">分类标识</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" value="{$info.name ?? ''}" lay-verify="required"
                                   placeholder="请输入内容" class="layui-input">
                            <div class="layui-form-mid layui-word-aux">英文字母</div>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">分组定义</label>
                        <div class="layui-input-block">
                                <textarea name="groups" placeholder="请输入内容"
                                          class="layui-textarea">{$info.groups ?? ''}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发布内容</label>
                        <div class="layui-input-block">
                            <input type="radio" name="allow_publish" value="0" title="不允许">
                            <input type="radio" name="allow_publish" value="1" title="仅允许后台" checked>
                            <input type="radio" name="allow_publish" value="2" title="允许前后台">
                        </div>
                        <div class="layui-form-mid layui-word-aux">是否允许发布内容</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否审核</label>
                        <div class="layui-input-block">
                            <input type="radio" name="check" value="0" title="不需要" checked>
                            <input type="radio" name="check" value="1" title="需要">
                        </div>
                        <div class="layui-form-mid layui-word-aux">在该分类下发布的内容是否需要审核</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">允许文档类型</label>
                        <div class="layui-input-block">
                            {volist name=":Config::get('config.document_model_type')" id="type"}
                            <input type="checkbox" name="type[{$i-1}]" title="{$type}" value="{$key}"
                                   lay-skin="primary">
                            {/volist}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">分类图标</label>
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" id="category_icon">
                                <i class="layui-icon">&#xe67c;</i>上传图片
                            </button>
                        </div>
                        <input type="hidden" name="icon" id="icon" value="{$info.icon ?? 0}">
                        <div class="layui-input-block picture" style="padding-top: 3px;">
                            <img src="{$info.icon|default=0|get_cover='path'}" alt="" height=114 width=185 id="category_pic" class="layui-upload-img {empty name="info.icon"}layui-hide{/empty}">
                            <p style="padding-top: 2px;" id="before"></p>
                        </div>

                    </div>
                </div>
            </div>
        </div>
        <div class="layui-tab-item">
            <div class="layui-row">
                <div class="layui-col-xs12 layui-col-md5">
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择框</label>
                        <div class="layui-input-block">
                            <select name="display" lay-verify="required">
                                <option value="0">不可见</option>
                                <option value="1">所有人可见</option>
                                <option value="2">管理员可见</option>
                            </select>
                            <div class="layui-form-mid layui-word-aux"> 是否对用户可见，针对前台</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" value="{$info.sort ?? 0}" placeholder="请输入内容"
                                   class="layui-input">
                            <div class="layui-form-mid layui-word-aux">仅对当前层级分类有效</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">列表行数</label>
                        <div class="layui-input-block">
                            <input type="text" name="list_row" value="{$info.list_row ?? ''}" placeholder="请输入内容"
                                   class="layui-input">
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">网页标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="meta_title" value="{$info.meta_title ?? ''}"
                                   placeholder="请输入内容" class="layui-input">
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">关键字</label>
                        <div class="layui-input-block">
                            <textarea name="groups" placeholder="关键字用英文','(逗号)隔开" class="layui-textarea">{$info.keywords ?? ''}</textarea>
                            <div class="layui-form-mid layui-word-aux">用英文逗号隔开</div>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">描述</label>
                        <div class="layui-input-block">
                            <textarea name="groups" placeholder="请输入内容"
                                      class="layui-textarea">{$info.description ?? ''}</textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">频道模板</label>
                        <div class="layui-input-block">
                            <input type="text" name="template_index" value="{$info.template_index ?? ''}"
                                   placeholder="请输入内容" class="layui-input">
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">列表模板</label>
                        <div class="layui-input-block">
                            <input type="text" name="template_lists" value="{$info.template_lists ?? ''}"
                                   placeholder="请输入内容" class="layui-input">
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">详情模板</label>
                        <div class="layui-input-block">
                            <input type="text" name="template_detail" value="{$info.template_detail ?? ''}"
                                   placeholder="请输入内容" class="layui-input">
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">编辑模板</label>
                        <div class="layui-input-block">
                            <input type="text" name="template_edit" value="{$info.template_edit ?? ''}"
                                   placeholder="名称不能为空" class="layui-input">
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{$info.id ?? ''}">
                <input type="hidden" name="pid" value="{$category.id ?? ''}">
                <input type="hidden" name="level" value="{$info.id ? $category.level:$category.level+1}">
                <button class="layui-btn" lay-submit lay-filter="category">立即提交</button>
                <button class="layui-btn layui-btn-primary retreat">取消</button>
            </div>
        </div>
    </form>
</div>
</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    UrlHighlight("{:Url::build('Category/index')}");
    '{present name="info.id"}'
    setChoose("allow_publish", "{$info->getData('allow_publish') ?? 1}");
    setChoose("check", "{$info->getData('check') ?? 0}");
    setChoose("display", "{$info->getData('display')}");
    var type={$info.type|explode = ',',###|json_encode|raw};
    if (type != ""){
        layui.use(['jquery'], function () {
            layui.$.each(type, function (i) {
                layui.$("input[name='type["+ i +"]']").attr("checked",true);
            });
        });
    }
    '{/present}'
    layui.use(['jquery','upload','form'], function () {
        //监听提交
        layui.form.on('submit(category)', function(data){
            layui.$.post(data.form.action, data.field, function (info) {
                status_load(info, data.elem);
            });
            return false;
        });

        //上传图片
        var before;
        var upload_pic= layui.upload.render({
            elem: '#category_icon',
            url:"{:Url::build('Category/categoryPicture')}",
            auto:false,
            bindAction:"#upload_pic",
            field:"categoryPicture",
            size:2048,
            choose:function (obj) {
                obj.preview(function (index,file,result) {
                    layui.$('#category_pic').attr('src', result).removeClass('layui-hide');
                    before = layui.$('#before');
                    before.html('<a class="layui-btn layui-btn-mini upload_pic">上传</a>');
                    before.find('.upload_pic').on('click', function(){
                        upload_pic.upload();
                    });
                });
            },
            before: function(obj){
               loading= layui.layer.load(2); //上传loading
            },
            done: function(res, index, upload){
                layui.layer.close(loading); //关闭loading
                if(res.code==1){
                    layui.layer.msg(res.msg);
                    layui.$('#category_pic').attr('src', res.data.path);
                    layui.$('#icon').val(res.data.id);
                } else {
                    layui.layer.msg(res.msg);
                    console.log(res);
                }
            }
        });
        layui.$('#category_pic').on('click',function () {
            layui.layer.photos({
                photos: ".picture"
            });
        });
    });
</script>
{/block}